<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>

    论坛：<div></div>
    <textarea name="" id="" cols="30" rows="10"></textarea>
    <button>发布</button>
    <script>
        
        /* 

            需求：需要对发布的信息中关键字进行过滤
         */
         const divObj = document.querySelector("div")
         const textareaObj = document.querySelector("textarea")
         const btnObj = document.querySelector("button")
         
         //对发布的信息过滤
         btnObj.addEventListener("click",function(){
             /* 
                g:表示全局替换
                i：忽略大小写
              */
             divObj.innerHTML = textareaObj.value.replace(/卧槽|傻瓜|sb/gi,'**')
         })

         /* 
            需求2：通过正则实现如下需求
                    日期：2022-11-12
                    像输出结果为：12-11-2022
          */

          const re1 = /(\d{4})-(\d{2})-(\d{2})/
          const strDate = "2022-12-31"
          /* 
                分别代表括号内的内容
                $1 =(\d{4}) 
                $2 =(\d{2}) 
                $3 =(\d{2}) 
           */
           //方式一
          const result = strDate.replace(re1,"$3/$2/$1")
        //   const result = strDate.replace(re1,"$3-$2-$1")
        //   const result = strDate.replace(re1,"$3*$2*$1")
          console.log(result)

          //方式二
         const result2 =  strDate.replace(re1,function(){
              return RegExp.$3+"-"+RegExp.$2+"-"+RegExp.$1
          })
          console.log(result2)

          //方式三
          const result3 =  strDate.replace(re1,function(match,year,month,day){
              console.log("match = "+match)         //第一个参数输出原来的数
              console.log("year = "+year)
              console.log("mouth = "+month)
              console.log("day = "+day)
              return day+"-"+month+"-"+year;
          })

          console.log(result3)
    </script>
</body>
</html>